package com.tarena.sentinel.study.demo02;

import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class SentinelDemo01 {
    public static void main(String[] args) {
        SpringApplication.run(SentinelDemo01.class,args);
        //在容器启动之后 设置sentinel规则.
        //定义一个规则 数组 流控规则FlowRule 熔断规则DegradeRule 系统规则SystemRule
        List<FlowRule> flowRules=new ArrayList<>();
        //生成一个 规则对象
        FlowRule flowRule=new FlowRule();
        //使用这个规则绑定过一个资源
        flowRule.setResource("sayHi");
        //设定 限流 方式 0=并发限流 1=qps限流
        flowRule.setGrade(1);
        //限流阈值
        flowRule.setCount(1);
        //添加到规则数组中,
        flowRules.add(flowRule);
        //sentinel加载这个数组.
        FlowRuleManager.loadRules(flowRules);
    }
}
